/**
 * Copyright (C) 2013 HalZhang
 */

package com.taropan.wallpaper.ui;

import com.taropan.wallpaper.R;
import com.taropan.wallpaper.util.Utils;

import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;

public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preferences);
        ListPreference listPreference = (ListPreference) findPreference(getString(R.string.preference_key_traffic));
        listPreference.setOnPreferenceChangeListener(this);
        listPreference.setSummary(listPreference.getEntry());

        ListPreference listPreference_change = (ListPreference) findPreference(getString(R.string.preference_key_auto_change));
        listPreference_change.setOnPreferenceChangeListener(this);
        listPreference_change.setSummary(listPreference_change.getEntry());
        
        ListPreference listPreference_download = (ListPreference) findPreference(getString(R.string.preference_key_auto_download));
        listPreference_download.setOnPreferenceChangeListener(this);
        listPreference_download.setSummary(listPreference_download.getEntry());
        
        
        ListPreference listPreference_electric = (ListPreference) findPreference(getString(R.string.preference_key_low_electric));
        listPreference_electric.setOnPreferenceChangeListener(this);
        listPreference_electric.setSummary(listPreference_electric.getEntry());
        
//        Preference versionPref = findPreference(getString(R.string.pref_key_version));
//        versionPref.setSummary(getString(R.string.pref_summary_version,
//                Utils.getVersionName(getApplicationContext())));
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (preference instanceof ListPreference) {
            ListPreference listPreference = (ListPreference) preference;
            preference.setSummary(listPreference.getEntries()[listPreference
                    .findIndexOfValue((String) newValue)]);
        }
        return true;
    }

}
